import axios from "axios";
import { ShowFail, ShowLoading, ShowSuccess } from '../utils/message'
// export const baseURL = 'http://192.168.57.160:3333'
export const baseURL = 'http://101.37.23.156:3333'
const request = axios.create({
    baseURL:baseURL
})

// 请求的拦截器 request
request.interceptors.request.use((config:any)=>{
    if(config.url!='https://m.maizuo.com/gateway' && config.url!='http://120.26.90.83:3000/captcha/sent' && config.url!='http://120.26.90.83:3000/captcha/verify' ){
        config.headers.token =  localStorage.getItem('calToken')?.replaceAll('"','');   // token 通过请求头带给 服务器  
    }
    ShowLoading()
    // 请求发送之前 
    return config;
},err=>{
    // 请求发送失败 
    ShowFail('请求失败')
    console.log(err)
})


// 响应的拦截器 res; 
request.interceptors.response.use(res => {
    // 响应成功
    // console.log(res.data)
    // ShowSuccess(res.data.msg)
    if(res.data.code==200){
        ShowSuccess(res.data.msg)
    }else{
        ShowFail(res.data.msg)
    }
    return res.data;
},err=>{
    // 响应失败 
    ShowFail('响应失败')
    console.log(err)
})

export default request